<template>
  <div class="login_container">
    <div class="login_box">
      <el-form class="login_form" :model="login_form" :rules="login_form_rules">
        <el-form-item>
          <span class="label">Login</span>
        </el-form-item>
        <el-form-item prop="user">
          <el-input prefix-icon="el-icon-user" placeholder="用户名" v-model="login_form.username"></el-input>
        </el-form-item>
        <el-from-item prop="password">
          <el-input
            prefix-icon="el-icon-lock"
            placeholder="密码"
            v-model="login_form.password"
            show-password
          ></el-input>
        </el-from-item>
        <el-form-item class="buttons">
          <el-button type="primary" @click="login">登录</el-button>
          <el-button type="primary" @click="register">注册</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      login_form: {
        username: "",
        password: ""
      },
      login_form_rules: {
        user: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          { min: 1, max: 10, message: "请输入正确用户名", trigger: "blur" }
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }]
      }
    };
  },
  watch: {},
  methods: {
    register() {
      this.$router.push("/register");
    },
    login() {
      this.$axios.post("login", this.login_form).then(res => {
        if (res.data.type === "success") {
          this.$message({
            message: "登录成功",
            type: res.data.type
          });
          const token = res.data.token;
          if(this.login_form.username === "000"){
          window.localStorage.setItem("privateKey","-----BEGIN RSA PRIVATE KEY-----MIIBPAIBAAJBAKnF81V7urvjOnUihWJNDWn424SKUSrHJ3tiyg3sc8ojBtXiHVLzlbCFxpyZJ9eMaZC5td6zYgRWWW8ec+OXvhMCAwEAAQJBAKVdPa5nDTUTmI4dqORd/xHYpyFLhNHxGEDzsbGsPgCFU3YBwMY0XYfNf8PNcMNWhanzMooIwrAYhFxC6AgpeEECIQDmJ65ocBl9WRE4/c6BJ14eVyaCNwFudUTcoLEfi8mH8wIhALzWdf6OZcvbExJVTin2qlh9PO3tJiPbH6JZGHMP2ZlhAiB1uUJapUxEc3R9xEUGhw57UnSeEminCVDJ0WAIFMZmxQIhAKSo9LaFAGqjmpuv2rpopd0HR2vIECvP1GPCALnEJl/BAiEAwFFJvWxvjyfmj9vdr9Tl2eoZeNjgiWU6uAhsZtNYrf8=-----END RSA PRIVATE KEY-----")
          }else{
          window.localStorage.setItem("privateKey","-----BEGIN RSA PRIVATE KEY-----MIIBPAIBAAJBAKPhUC0E6oaXEV2KpDPQqSBz7WctH6E6nx74FNZj5JjG3bG+H0fl8+20MjLs5NdhdVwFtdsdUcf4+tnHfgDc3YsCAwEAAQJABsBlmTU2pEzc/kmT8j6KeTfNdA672tybaZ823I5JALI/bg5ZfUnVAwo+vVqmZYgXPQxdj9vC+fTuGWqpXzShIQIhAP9ThvbuPjUpo96JevCOi9m2tVvl7b2nVdyj6I7K5DP/AiEApFADnxe6fXNaHRYpKPv8+lpCEkGrtPXKLSiGTXgm5nUCIQC+dJn6XCC/Gz6HY1n3Uv1y+10xHcRHcikUGpgA28t6FQIhAKCkXbYH09rckQiI5vrbygvVfG0u6TnFZ8FYsl1BD/8VAiEAi5QPZS9m1KH3fxTMBdBaJxEcYbA9nDoTjgMQK1NUp0c=-----END RSA PRIVATE KEY-----")
          }
          window.localStorage.removeItem("token")
          window.localStorage.setItem("token", token);
          this.$router.push("/home");
        } else if (res.data.type === "error") {
          this.$message({
            message: res.data.content,
            type: res.data.type
          });
        }
      });
    }
  }
};
</script>

<style  scoped>
.login_container {
  background-color: #ffffff;
  height: 100%;
}
.login_box {
  width: 450px;
  height: 270px;
  background-color: #fff;
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 5px 3px rgb(221, 221, 221);
}
.label {
  text-align: center;
  display: block;
  font-size: 22px;
  font-weight: bold;
  color: rgb(105, 105, 105);
}
.buttons {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

.login_form {
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 0 40px;
  box-sizing: border-box;
}
</style>